public class Solution8 {
    //714. 买卖股票的最佳时机含手续费
    public int maxProfit(int[] prices, int fee) {
        int n = prices.length;
        int[] f = new int[n];  //买入
        int[] g = new int[n];  //卖出
        f[0] = -prices[0];
        for (int i = 1; i < n; i++) {
            f[i] = Math.max(g[i-1]-prices[i],f[i-1]);
            g[i] = Math.max(g[i-1],prices[i]+f[i-1]-fee);
        }
        return g[n-1];
    }
}
